﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Code;
using DB;
using Microsoft.AspNetCore.Mvc;
using Models;

namespace LayuiAdmin.Controllers {
    public class NoticeController : Controller {
        public IActionResult NoticeEdit(int Id, NoticeType type) {
            Notice notice = new Notice();

            ViewData["Title"] = type == NoticeType.购买协议 ? "编辑购买协议" : "编辑交流公告";
            ViewData["type"] = type;

            using (var context = new SqlServerDB()) {
                if (Id == 0 && type == NoticeType.购买协议) {
                    notice = context.Notices.FirstOrDefault(m => m.NoticeType == NoticeType.购买协议);
                } else if (Id > 0) {
                    notice = context.Notices.FirstOrDefault(m => m.Id == Id);
                }
            }

            return View(notice);
        }

        public IActionResult List() {
            ViewBag.UserType = (UserTypes)Convert.ToInt32(HttpContext.User.Identity.GetValue("UserType"));

            return View();
        }
    }
}